package demo.springcloud.product.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class HomeController {
    @Value("${server.port}")
    private String port;
    @GetMapping("/index")
    public String index(HttpServletRequest request){

        //throw new RuntimeException("test producter app");
       //log.error("---------------------------    trace2   ----------------------------------");
//        log.info(" \n  TraceId={} \n  SpanId={} \n  ParentSpanId={} \n  Sampled={} \n  Name={}"
//                , request.getHeader("X-B3-TraceId")
//                , request.getHeader("X-B3-SpanId")
//                , request.getHeader("X-B3-ParentSpanId")
//                , request.getHeader("X-B3-Sampled")
//                , request.getHeader("X-Span-Name"));
        log.trace("this is trace");
        log.info("this is info");
        log.debug("this is debug");
        log.error("this is error");
        return "Trace-port:" + port;

    }

    @GetMapping("/aa/index2")
    public String index2(){
        return "this is home2";
    }
    @GetMapping("/index3")
    public String index3(){
        return "this is home3";
    }

    @GetMapping("/bb")
    @SentinelResource("b")
    public String basic(String a,String b){
        log.info("basic......");
        return a + ":" + b;
    }

}
